import matplotlib.pyplot as plt
import math
import numpy as np

class Q:
 
    def __init__(self):
        self.A = 4.0817
        self.B = 4.0817
        self.phi = 0.125
        self.alpha = 0.43
        self.beta = 0.78
        self.theta = 0.576
        
        # self.h = 1
        # self.phi1 = 1
        # self.phi2 = 1
        self.gamma = 0.65
        
        # self.Ltop = 1 
        # self.Lbottom = 1 
        # self.R = 1
        # self.Rindex = 1
    
    def C27(self,_ROU):
        
        self.rou  = _ROU
        GT = self.A * self.phi * self.rou
        GT = GT * self.beta * (1 - self.alpha)
        
        GB = self.gamma * (1 - self.theta)
        self.phi1 = GT / GB
        
        
        KT = pow(self.A,self.theta)
        KT = KT * self.B
        KT = KT * pow(self.phi,self.theta)
        KT = KT * pow(self.theta,self.theta)
        KT = KT * pow((1-self.alpha),self.theta)
        
        KB = 1 - self.theta
        KB = pow(KB,self.theta)
        
        self.phi2 = KT / KB
        
        _L = pow(self.phi1 ,self.alpha * self.theta)
        _L = _L * pow(self.phi2,(1-self.alpha))
        
        _index = 1 - self.alpha * (1-self.theta)
        _index = 1 / _index  
        _R27 =  pow( _L ,_index )
        return _R27
        
        
    def C29(self):
        
        self.Ltop = pow(self.A,2)*self.phi
        self.Ltop = self.Ltop * self.beta * self.theta
        self.Ltop = self.Ltop * pow((1-self.alpha),2)
        self.Ltop = self.Ltop * self.h
        
        self.Lbottom = self.gamma * pow((1-self.theta),2)
        self.Lbottom = self.gamma * (1-self.alpha*(1-self.theta))
        
        self.Rindex = self.alpha * (2-self.theta) - 1
        self.Rindex = self.Rindex/(1-self.alpha*(1-self.theta))
        
        self.R = self.phi1/self.phi2
        self.R = pow(self.R,self.Rindex)
        
        
        
        _R29 = self.Ltop / self.Lbottom * self.R 
        return _R29
    
    def C11(self,_ROU):
        
        self._ROU = _ROU
        _NT = (1 - self.alpha) * self.gamma
        _NB = 1 + self._ROU * self.beta + self.gamma
        _NB = _NB * self.phi
        
        _R11 = _NT / _NB
        return _R11
        

_d = Q()

print(_d.C27(0.1))

X_ROU = np.linspace(0,1,100)

X_ROU = np.linspace(0,1,100)
Y_I = np.empty(100, dtype = float)
Y_n = np.empty(100, dtype = float)

for i in range(0,100):
    _d = Q()
    Y_I[i]=_d.C27(X_ROU[i])
    Y_n[i]=_d.C11(X_ROU[i])
    # print(Y[i])

plt.figure(figsize=(12,6))
plt.subplot(1,2,1)
plt.title("func 27")
plt.xlabel("ρ")
plt.ylabel("I")
plt.plot(X_ROU,Y_I)

plt.subplot(1,2,2)
plt.title("func 11")
plt.xlabel("ρ")
plt.ylabel("n")
plt.plot(X_ROU,Y_n)


plt.show()
    